"""电影应用工具模块

包含电影应用中使用的辅助函数和工具类。
"""

from contextlib import contextmanager

from django.core.files.storage import default_storage


@contextmanager
def temporary_file(uploaded_file):
    """
    临时文件上下文管理器

    Args:
        uploaded_file: 上传的文件对象

    Yields:
        str: 临时文件路径
    """
    try:
        file_name = default_storage.save(uploaded_file.name, uploaded_file)
        file_path = default_storage.path(file_name)
        yield file_path
    finally:
        default_storage.delete(file_name)
